<template>
  <div style="width: 100%; height: 400px"></div>
</template>

<script>
import * as echarts from 'echarts'
import resize from '@/mixins/resize'
import { getAppStatistics } from '@/api/developer'
export default {
  mixins: [resize],
  data() {
    return {
      developerId: this.$route.params.developerId,
      xAxisData: [],
      yAxisData: [],
      chart: null
    }
  },
  methods: {
    initData() {
      getAppStatistics(this.developerId)
        .then((res) => {
          if (res) {
            this.xAxisData = res.xAxisData
            this.yAxisData = res.seriesList
            this.initChart()
          }
        })
        .catch(this.$confirmError)
      // this.xAxisData = ['Oct 1', 'Oct 2', 'Oct 3', 'Oct 4', 'Oct 5', 'Oct 6', 'Oct 7']
      // this.yAxisData = [
      //   {
      //     name: 'TOMS1',
      //     stack: 'APP',
      //     data: [25, 30, 40, 15, 28, 31, 12],
      //     type: 'bar',
      //     barWidth: 75
      //   },
      //   {
      //     name: 'TOMS2',
      //     stack: 'APP',
      //     data: [25, 30, 40, 15, 28, 31, 12],
      //     type: 'bar',
      //     barWidth: 75
      //   },
      //   {
      //     name: 'TOMS3',
      //     stack: 'APP',
      //     data: [25, 30, 40, 15, 28, 31, 12],
      //     type: 'bar',
      //     barWidth: 75
      //   }
      // ]
      this.initChart()
    },
    initChart() {
      this.chart = echarts.init(this.$el)
      const option = {
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'shadow'
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: {
          type: 'category',
          data: this.xAxisData
        },
        yAxis: {
          minInterval: 1,
          type: 'value'
        },
        series: this.yAxisData,
        legend: {}
      }
      this.chart.setOption(option)
    }
  },
  mounted() {
    this.initData()
  }
}
</script>

<style>
</style>
